; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --version 2
; RUN: opt -passes=newgvn -S < %s | FileCheck %s

define i32 @test1(ptr %p) {
; CHECK-LABEL: define i32 @test1
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG0:![0-9]+]]
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !0
  %b = load i32, ptr %p, !range !0
  %c = add i32 %a, %b
  ret i32 %c
}

define i32 @test2(ptr %p) {
; CHECK-LABEL: define i32 @test2
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !0
  %b = load i32, ptr %p
  %c = add i32 %a, %b
  ret i32 %c
}

define i32 @test3(ptr %p) {
; CHECK-LABEL: define i32 @test3
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG1:![0-9]+]]
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !0
  %b = load i32, ptr %p, !range !1
  %c = add i32 %a, %b
  ret i32 %c
}

define i32 @test4(ptr %p) {
; CHECK-LABEL: define i32 @test4
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG2:![0-9]+]]
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !0
  %b = load i32, ptr %p, !range !2
  %c = add i32 %a, %b
  ret i32 %c
}

define i32 @test5(ptr %p) {
; CHECK-LABEL: define i32 @test5
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG3:![0-9]+]]
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !3
  %b = load i32, ptr %p, !range !4
  %c = add i32 %a, %b
  ret i32 %c
}

define i32 @test6(ptr %p) {
; CHECK-LABEL: define i32 @test6
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG4:![0-9]+]]
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !5
  %b = load i32, ptr %p, !range !6
  %c = add i32 %a, %b
  ret i32 %c
}

define i32 @test7(ptr %p) {
; CHECK-LABEL: define i32 @test7
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG5:![0-9]+]]
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !7
  %b = load i32, ptr %p, !range !8
  %c = add i32 %a, %b
  ret i32 %c
}

define i32 @test8(ptr %p) {
; CHECK-LABEL: define i32 @test8
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4
; CHECK-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT:    ret i32 [[C]]
;
  %a = load i32, ptr %p, !range !9
  %b = load i32, ptr %p, !range !10
  %c = add i32 %a, %b
  ret i32 %c
}


!0 = !{i32 0, i32 2}
!1 = !{i32 3, i32 5}
!2 = !{i32 2, i32 5}
!3 = !{i32 -5, i32 -2}
!4 = !{i32 1, i32 5}
!5 = !{i32 10, i32 1}
!6 = !{i32 12, i32 16}
!7 = !{i32 1, i32 2, i32 3, i32 4}
!8 = !{i32 5, i32 1}
!9 = !{i32 1, i32 5}
!10 = !{i32 5, i32 1}
;.
; CHECK: [[RNG0]] = !{i32 0, i32 2}
; CHECK: [[RNG1]] = !{i32 0, i32 2, i32 3, i32 5}
; CHECK: [[RNG2]] = !{i32 0, i32 5}
; CHECK: [[RNG3]] = !{i32 -5, i32 -2, i32 1, i32 5}
; CHECK: [[RNG4]] = !{i32 10, i32 1}
; CHECK: [[RNG5]] = !{i32 3, i32 4, i32 5, i32 2}
;.
